package a.a.a;

import static com.besome.sketch.Config.VAR_DEFAULT_MIN_SDK_VERSION;
import static com.besome.sketch.Config.VAR_DEFAULT_TARGET_SDK_VERSION;
import static mod.hey.studios.util.ProjectFile.getDefaultColor;

import android.content.Context;
import android.util.Log;

import com.besome.sketch.beans.BlockBean;
import com.besome.sketch.beans.ComponentBean;
import com.besome.sketch.beans.ProjectFileBean;
import com.besome.sketch.beans.ProjectLibraryBean;
import com.besome.sketch.beans.SrcCodeBean;
import com.besome.sketch.beans.ViewBean;
import com.besome.sketch.editor.manage.library.material3.Material3LibraryManager;

import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Pattern;

import mod.hey.studios.build.BuildSettings;
import mod.hey.studios.project.ProjectSettings;
import mod.hey.studios.util.ProjectFile;
import mod.hilal.saif.blocks.CommandBlock;
import mod.pranav.viewbinding.ViewBindingBuilder;
import pro.sketchware.SketchApplication;
import pro.sketchware.util.library.BuiltInLibraryManager;
import pro.sketchware.utility.FileUtil;
import pro.sketchware.xml.XmlBuilder;
import pro.sketchware.xml.XmlBuilderHelper;

public class yq {

    /**
     * Firebase Database storage location RegExp matcher to remove unwanted parts of storage URL
     * to get the actual project ID.
     * <p/>
     * Users should enter the entire storage URL without <code>https://</code> at the beginning and
     * <code>/</code> at the end, e.g. <code>sk-pro-default-rtdb.firebaseio.com</code>.
     */
    private static final String FIREBASE_DATABASE_STORAGE_LOCATION_MATCHER = "(-default-rtdb)?\\.[a-z](.?)+";
    private static final Pattern PACKAGE_PLACEHOLDER_PATTERN = Pattern.compile("<\\?package_name\\?>");

    /**
     * Example content: /storage/emulated/0/.sketchware/mysc/605/app/src/main/assets
     */
    public final String assetsPath;

    /**
     * Example content: /storage/emulated/0/.sketchware/mysc/605/app/src/main/assets/fonts
     */
    public final String fontsPath;

    /**
     * Path of ZIP file containing compiled resources of the current project,
     * e.g. /storage/emulated/0/.sketchware/mysc/605/bin/InternalDemo.apk.res
     */
    public final String resourcesApkPath;

    /**
     * Example content: /storage/emulated/0/.sketchware/mysc/605/bin/classes.dex
     */
    public final String classesDexPath;

    /**
     * Example content: /storage/emulated/0/.sketchware/mysc/605/bin/InternalDemo.apk.unsigned
     */
    public final String unsignedUnalignedApkPath;

    /**
     * Example content: /storage/emulated/0/.sketchware/mysc/605/bin/InternalDemo.apk
     */
    public final String finalToInstallApkPath;

    /**
     * Example content: /storage/emulated/0/sketchware/signed_apk/InternalDemo_release.apk
     */
    public final String releaseApkPath;
    /**
     * Example content: /storage/emulated/0/.sketchware/mysc/605/bin/InternalDemo.apk.unsigned.aligned
     */
    public final String unsignedAlignedApkPath;
    public final String sc_id;
    /**
     * Example content: /storage/emulated/0/.sketchware/mysc/605/
     */
    public final String projectMyscPath;
    public final String projectName;
    public final String packageName;
    public final String applicationName;
    public final int colorAccent;
    public final int colorPrimary;
    public final int colorPrimaryDark;
    public final int colorControlHighlight;
    public final int colorControlNormal;
    public final String versionCode;
    public final String versionName;
    /**
     * Package name of current project,
     * but "folders" separated with slashes (/) instead of periods (.),
     * e.g. com/jbk/internal/demo
     */
    public final String packageNameAsFolders;
    /**
     * Path of file with ProGuard rules automatically generated by aapt2,
     * e.g. /storage/emulated/0/.sketchware/mysc/605/bin/aapt_rules.pro
     */
    public final String proguardAaptRules;
    /**
     * Path of ProGuard rules auto-generated to exclude built-in libraries and non-Full Mode Local libraries,
     * e.g. /storage/emulated/0/.sketchware/mysc/605/bin/rules_generated.pro
     */
    public final String proguardAutoGeneratedExclusions;
    /**
     * ProGuarded classes.jar file's path of current project,
     * e.g. /storage/emulated/0/.sketchware/mysc/605/bin/classes_proguard.jar
     */
    public final String proguardClassesPath;
    /**
     * Path of file containing the ProGuard mapping,
     * e.g. /storage/emulated/0/.sketchware/mysc/605/bin/mapping.txt
     */
    public final String proguardMappingPath;
    /**
     * Path of file containing ProGuard seeds,
     * e.g. /storage/emulated/0/.sketchware/mysc/605/bin/seeds.txt
     */
    public final String proguardSeedsPath;
    /**
     * Path of file containing ProGuard usage,
     * e.g. /storage/emulated/0/.sketchware/mysc/605/bin/usage.txt
     */
    public final String proguardUsagePath;
    /**
     * Current project's ProjectSettings object
     */
    public final ProjectSettings projectSettings;
    /**
     * Example content: /storage/emulated/0/.sketchware/mysc/605/app/src/main/AndroidManifest.xml
     */
    public final String androidManifestPath;
    /**
     * Example content: /storage/emulated/0/.sketchware/mysc/605/app/src/main
     */
    public final String generatedFilesPath;
    /**
     * Example content: /storage/emulated/0/.sketchware/mysc/605/bin
     */
    public final String binDirectoryPath;
    /**
     * Example content: /storage/emulated/0/.sketchware/mysc/605/bin/classes
     */
    public final String compiledClassesPath;
    /**
     * Project's generated R.java files directory,
     * e.g. /storage/emulated/0/.sketchware/mysc/605/gen
     */
    public final String rJavaDirectoryPath;
    /**
     * Example content: /storage/emulated/0/.sketchware/mysc/605/app/src/main/res
     */
    public final String resDirectoryPath;
    /**
     * Example content: /storage/emulated/0/.sketchware/mysc/605/app/src/main/proguard-rules.pro
     */
    public final String proguardFilePath;
    /**
     * Example content: /storage/emulated/0/.sketchware/mysc/605/app/src/main/res/layout
     */
    public final String layoutFilesPath;
    /**
     * Example content: /storage/emulated/0/.sketchware/mysc/605/app/src/main/java
     */
    public final String javaFilesPath;
    /**
     * Example content: /storage/emulated/0/.sketchware/mysc/605/app/src/main/res/raw
     */
    public final String importedSoundsPath;
    public final HashMap<String, Object> metadata;
    private final Material3LibraryManager material3LibraryManager;
    private final oB fileUtil;
    private final Context context;
    public jq N;
    public boolean generateDataBindingClasses;
    public boolean isAndroidStudioExport;
    private ExportType exportingType;

    public yq(Context context, String sc_id) {
        this(context, wq.d(sc_id), lC.b(sc_id));
    }

    public yq(Context context, String myscFolderPath, HashMap<String, Object> metadata) {
        this.context = context;
        this.metadata = metadata;
        N = new jq();
        sc_id = yB.c(metadata, "sc_id");
        material3LibraryManager = new Material3LibraryManager(sc_id);
        N.sc_id = sc_id;
        projectMyscPath = myscFolderPath.endsWith(File.separator) ? myscFolderPath : myscFolderPath + File.separator;
        packageName = yB.c(metadata, "my_sc_pkg_name");
        projectName = yB.c(metadata, "my_ws_name");
        applicationName = yB.c(metadata, "my_app_name");
        versionCode = yB.c(metadata, "sc_ver_code");
        versionName = yB.c(metadata, "sc_ver_name");

        colorAccent = yB.a(metadata, ProjectFile.COLOR_ACCENT, getDefaultColor(ProjectFile.COLOR_ACCENT));
        colorPrimary = yB.a(metadata, ProjectFile.COLOR_PRIMARY, getDefaultColor(ProjectFile.COLOR_PRIMARY));
        colorPrimaryDark = yB.a(metadata, ProjectFile.COLOR_PRIMARY_DARK, getDefaultColor(ProjectFile.COLOR_PRIMARY_DARK));
        colorControlHighlight = yB.a(metadata, ProjectFile.COLOR_CONTROL_HIGHLIGHT, getDefaultColor(ProjectFile.COLOR_CONTROL_HIGHLIGHT));
        colorControlNormal = yB.a(metadata, ProjectFile.COLOR_CONTROL_NORMAL, getDefaultColor(ProjectFile.COLOR_CONTROL_NORMAL));

        projectSettings = new ProjectSettings(sc_id);
        fileUtil = new oB(true);
        packageNameAsFolders = packageName.replaceAll("\\.", File.separator);
        binDirectoryPath = projectMyscPath + "bin";
        compiledClassesPath = binDirectoryPath + File.separator + "classes";
        proguardClassesPath = binDirectoryPath + File.separator + "classes_proguard.jar";
        proguardAaptRules = binDirectoryPath + File.separator + "aapt_rules.pro";
        proguardSeedsPath = binDirectoryPath + File.separator + "seeds.txt";
        proguardUsagePath = binDirectoryPath + File.separator + "usage.txt";
        proguardMappingPath = binDirectoryPath + File.separator + "mapping.txt";
        proguardAutoGeneratedExclusions = binDirectoryPath + File.separator + "rules_generated.pro";
        rJavaDirectoryPath = projectMyscPath + "gen";
        generatedFilesPath = projectMyscPath + "app" + File.separator + "src" + File.separator + "main";
        javaFilesPath = generatedFilesPath + File.separator + "java";
        resDirectoryPath = generatedFilesPath + File.separator + "res";
        proguardFilePath = projectMyscPath + "app" + File.separator + "proguard-rules.pro";
        layoutFilesPath = resDirectoryPath + File.separator + "layout";
        importedSoundsPath = resDirectoryPath + File.separator + "raw";
        assetsPath = generatedFilesPath + File.separator + "assets";
        fontsPath = assetsPath + File.separator + "fonts";
        androidManifestPath = projectMyscPath + "app" + File.separator + "src" + File.separator + "main" + File.separator + "AndroidManifest.xml";
        resourcesApkPath = binDirectoryPath + File.separator + projectName + ".apk.res";
        classesDexPath = binDirectoryPath + File.separator + "classes.dex";
        unsignedUnalignedApkPath = binDirectoryPath + File.separator + projectName + ".apk.unsigned";
        unsignedAlignedApkPath = unsignedUnalignedApkPath + ".aligned";
        finalToInstallApkPath = binDirectoryPath + File.separator + projectName + ".apk";
        releaseApkPath = wq.o() + File.separator + projectName + "_release.apk";
    }

    /**
     * Deletes the directory {@link yq#resDirectoryPath}/values-v21/.
     */
    public void a() {
        File file = new File(resDirectoryPath + File.separator + "values-v21");
        if (file.exists()) {
            fileUtil.a(file);
        }
    }

    /**
     * Creates needed build directories {@link yq#binDirectoryPath}, {@link yq#compiledClassesPath}, {@link yq#rJavaDirectoryPath}, {@link yq#javaFilesPath}, {@link yq#resDirectoryPath},
     * {@link yq#layoutFilesPath}, {@link yq#importedSoundsPath}, {@link yq#assetsPath}, and {@link yq#fontsPath}.
     */
    public void c(Context context) {
        fileUtil.f(binDirectoryPath);
        fileUtil.f(compiledClassesPath);
        fileUtil.f(rJavaDirectoryPath);
        fileUtil.f(javaFilesPath);
        fileUtil.f(resDirectoryPath);
        fileUtil.f(layoutFilesPath);
        fileUtil.f(importedSoundsPath);
        fileUtil.f(assetsPath);
        fileUtil.f(fontsPath);
    }

    /**
     * Prepares to compile and creates /Internal storage/.sketchware/mysc/&lt;sc_id&gt;/ directories,
     * {@link yq#binDirectoryPath}, {@link yq#compiledClassesPath} and {@link yq#rJavaDirectoryPath}.
     */
    public void e() {
        fileUtil.f(binDirectoryPath);
        fileUtil.f(compiledClassesPath);
        fileUtil.f(rJavaDirectoryPath);
    }

    /**
     * Deletes temporary compile cache directories, {@link yq#binDirectoryPath} and {@link yq#rJavaDirectoryPath}. The used method
     * logs all files and folders which get deleted.
     */
    public void f() {
        fileUtil.b(binDirectoryPath);
        fileUtil.b(rJavaDirectoryPath);
    }

    /**
     * Generates top-level build.gradle, build.gradle for module ':app' and settings.gradle files.
     */
    public void generateGradleFiles() {
        fileUtil.b(projectMyscPath + File.separator + "app" + File.separator + "build.gradle",
                Lx.getBuildGradleString(VAR_DEFAULT_TARGET_SDK_VERSION, VAR_DEFAULT_MIN_SDK_VERSION, projectSettings.getValue(ProjectSettings.SETTING_TARGET_SDK_VERSION, String.valueOf(VAR_DEFAULT_TARGET_SDK_VERSION)), N, projectSettings.getValue(ProjectSettings.SETTING_ENABLE_VIEWBINDING, ProjectSettings.SETTING_GENERIC_VALUE_FALSE).equals(ProjectSettings.SETTING_GENERIC_VALUE_TRUE)));
        fileUtil.b(projectMyscPath + File.separator + "settings.gradle", Lx.a());
        fileUtil.b(projectMyscPath + File.separator + "build.gradle", Lx.c("8.12.0", "4.4.3"));

        fileUtil.b(projectMyscPath + File.separator + "gradle.properties", """
                android.enableR8.fullMode=false
                android.enableJetifier=true
                android.useAndroidX=true
                """.trim());
    }

    /**
     * Extracts a ZIP archive from assets to {@link yq#resDirectoryPath}.
     */
    public void a(Context context, String str) {
        try {
            KB.a(context, str, resDirectoryPath);
        } catch (Exception e2) {
            Log.e("ERROR", e2.getMessage(), e2);
        }
    }

    /**
     * Copies a file to the project's app icon path, {@link yq#resDirectoryPath}/drawable-xhdpi/app_icon.png
     */
    public void a(String iconPath) {
        try {
            fileUtil.a(iconPath, resDirectoryPath + File.separator + "mipmap-xhdpi" + File.separator + "ic_launcher.png");
        } catch (Exception e2) {
            e2.printStackTrace();
        }
    }

    /**
     * Copies a mipMaps folder to the project's app icon path, {@link yq#resDirectoryPath}/mipmap
     */

    public void aa(String iconPath) {
        try {
            FileUtil.copyDirectory(new File(iconPath), new File(resDirectoryPath + File.separator));
        } catch (Exception e2) {
            e2.printStackTrace();
        }
    }

    /**
     * Creates ic_launcher.xml to the project's app icon path, {@link yq#resDirectoryPath}/mipmap-anydpi-v26
     */

    public void createLauncherIconXml(String content) {
        try {
            fileUtil.b(resDirectoryPath + File.separator + "mipmap-anydpi-v26" + File.separator + "ic_launcher.xml", content);
        } catch (Exception e2) {
            e2.printStackTrace();
        }
    }

    /**
     * Generates DebugActivity.java, SketchApplication.java, and SketchLogger.java, if necessary.
     */
    public void generateDebugFiles(Context context) {
        boolean logcatEnabled = N.isDebugBuild && new BuildSettings(sc_id).getValue(
                        BuildSettings.SETTING_ENABLE_LOGCAT, BuildSettings.SETTING_GENERIC_VALUE_TRUE)
                .equals(BuildSettings.SETTING_GENERIC_VALUE_TRUE);

        String javaDir = FileUtil.getExternalStorageDir() + "/.sketchware/data/" + sc_id + "/files/java/";

        File debugActivityFile = new File(javaDir, "DebugActivity.java");
        if (!debugActivityFile.exists()) {
            String debugActivityContent = fileUtil.b(
                    context,
                    "debug" + File.separator + "DebugActivity.java"
            );
            debugActivityContent = PACKAGE_PLACEHOLDER_PATTERN.matcher(debugActivityContent).replaceAll(packageName);
            fileUtil.b(javaFilesPath + File.separator + packageNameAsFolders + File.separator + "DebugActivity.java", debugActivityContent);
        }

        String customApplicationClassName = new ProjectSettings(sc_id).getValue(
                ProjectSettings.SETTING_APPLICATION_CLASS, ".SketchApplication");
        boolean notUsingCustomApplicationClass = customApplicationClassName.equals(".SketchApplication");

        if (!customApplicationClassName.startsWith(".")) {
            customApplicationClassName = "." + customApplicationClassName; // since sketchware don't allow creating any java file outside the package name
        }

        String fullCustomClassName = packageName + customApplicationClassName;

        int lastDot = fullCustomClassName.lastIndexOf('.');
        String customClassSimpleName = fullCustomClassName.substring(lastDot + 1);
        String customClassPackage = fullCustomClassName.substring(0, lastDot);
        String customClassPackageAsFolders = customClassPackage.replace('.', File.separatorChar);

        File targetApplicationFile = new File(javaDir + File.separator +
                customApplicationClassName.substring(1).replace('.', '/') + ".java");

        if (!targetApplicationFile.exists()) {
            boolean applyMultiDex = projectSettings.getMinSdkVersion() < 21;
            String sketchApplicationFileContent = fileUtil.b(
                    context,
                    "debug" + File.separator + "SketchApplication.java"
            );
            sketchApplicationFileContent = PACKAGE_PLACEHOLDER_PATTERN.matcher(sketchApplicationFileContent).replaceAll(packageName);

            if (applyMultiDex) {
                sketchApplicationFileContent = sketchApplicationFileContent.replaceAll(
                        "Application \\{", "androidx.multidex.MultiDexApplication {");
            }
            if (logcatEnabled) {
                sketchApplicationFileContent = sketchApplicationFileContent.replace(
                                "super.onCreate();", "SketchLogger.startLogging();\n        super.onCreate();")
                        .replace("Process.killProcess(Process.myPid());",
                                "SketchLogger.broadcastLog(Log.getStackTraceString(throwable));\n" +
                                        "                    Process.killProcess(Process.myPid());"
                        );
            }
            if (new Material3LibraryManager(sc_id).isDynamicColorsEnabled()) {
                sketchApplicationFileContent = sketchApplicationFileContent.replace(
                                "mApplicationContext = getApplicationContext();",
                                "mApplicationContext = getApplicationContext();\n        DynamicColors.applyToActivitiesIfAvailable(this);")
                        .replace("import android.util.Log;", "import android.util.Log;\nimport com.google.android.material.color.DynamicColors;");
            }
            if (!notUsingCustomApplicationClass) {
                sketchApplicationFileContent = sketchApplicationFileContent.replaceAll(
                        "public class SketchApplication", "public class " + customClassSimpleName);
                sketchApplicationFileContent = sketchApplicationFileContent.replaceAll(
                        "package " + packageName + ";", "package " + customClassPackage + ";");

                String imports = "import android.util.Log;\nimport " + packageName + ".DebugActivity;";
                if (logcatEnabled) {
                    imports += "\nimport " + packageName + ".SketchLogger;";
                }
                sketchApplicationFileContent = sketchApplicationFileContent.replace(
                        "import android.util.Log;", imports);
            }

            fileUtil.b(javaFilesPath + File.separator
                    + customClassPackageAsFolders + File.separator
                    + customClassSimpleName + ".java", sketchApplicationFileContent);
        }

        if (logcatEnabled) {
            File sketchLoggerFile = new File(javaDir, "SketchLogger.java");
            if (!sketchLoggerFile.exists()) {
                String sketchLoggerFileContent = fileUtil.b(
                        context,
                        "debug" + File.separator + "SketchLogger.java"
                );

                sketchLoggerFileContent = PACKAGE_PLACEHOLDER_PATTERN.matcher(sketchLoggerFileContent).replaceAll(packageName);

                sketchLoggerFileContent = sketchLoggerFileContent.replace("<?class_name_package?>", customClassPackage);

                sketchLoggerFileContent = sketchLoggerFileContent.replace("<?class_name?>", customClassSimpleName);

                fileUtil.b(javaFilesPath + File.separator + packageNameAsFolders + File.separator + "SketchLogger.java",
                        sketchLoggerFileContent);
            }
        }
    }

    /**
     * Writes a project file to its correct location. Java files, for example, get saved to
     * <pre>
     *     {@link yq#javaFilesPath} + File.separator + {@link yq#packageNameAsFolders}
     * </pre>, while AndroidManifest.xml gets saved to {@link yq#androidManifestPath}.
     */
    public void a(String fileName, String fileContent) {
        if (fileName.endsWith("java")) {
            fileUtil.b(javaFilesPath + File.separator + packageNameAsFolders + File.separator + fileName, fileContent);
        } else if (fileName.equals("AndroidManifest.xml")) {
            fileUtil.b(androidManifestPath, fileContent);
        } else if (fileName.equals("colors.xml") || fileName.equals("styles.xml") || fileName.equals("strings.xml")) {
            fileUtil.b(resDirectoryPath + File.separator + "values" + File.separator + fileName, fileContent);
        } else if (fileName.equals("provider_paths.xml")) {
            fileUtil.b(resDirectoryPath + File.separator + "xml" + File.separator + fileName, fileContent);
        } else {
            fileUtil.b(layoutFilesPath + File.separator + fileName, fileContent);
        }
    }

    /**
     * Initialize project metadata
     */
    public void a(iC projectLibraryManager, hC projectFileManager, eC projectDataManager) {
        a(projectLibraryManager, projectFileManager, projectDataManager, ExportType.DEBUG_APP);
    }

    public void a(iC projectLibraryManager, hC projectFileManager, eC projectDataManager, ExportType exportingType) {
        ProjectLibraryBean adMob = projectLibraryManager.b();
        ProjectLibraryBean appCompat = projectLibraryManager.c();
        ProjectLibraryBean firebase = projectLibraryManager.d();
        ProjectLibraryBean googleMaps = projectLibraryManager.e();
        this.exportingType = exportingType;
        N = new jq();
        N.packageName = packageName;
        N.projectName = applicationName;
        N.versionCode = versionCode;
        N.versionName = versionName;
        N.sc_id = sc_id;
        N.isDebugBuild = exportingType == ExportType.DEBUG_APP;
        isAndroidStudioExport = exportingType == ExportType.ANDROID_STUDIO;
        generateDataBindingClasses = !(exportingType == ExportType.DEBUG_APP || exportingType == ExportType.ANDROID_STUDIO);
        if (firebase.useYn.equals(ProjectLibraryBean.LIB_USE_Y)) {
            N.isFirebaseEnabled = true;
            N.addPermission(jq.PERMISSION_INTERNET);
            N.addPermission(jq.PERMISSION_ACCESS_NETWORK_STATE);
        }
        if (appCompat.useYn.equals(ProjectLibraryBean.LIB_USE_Y)) {
            N.g = true;
        }
        if (adMob.useYn.equals(ProjectLibraryBean.LIB_USE_Y)) {
            N.isAdMobEnabled = true;
            N.addPermission(jq.PERMISSION_INTERNET);
            N.addPermission(jq.PERMISSION_ACCESS_NETWORK_STATE);
            N.setupAdmob(adMob);
        }
        if (googleMaps.useYn.equals(ProjectLibraryBean.LIB_USE_Y)) {
            N.isMapUsed = true;
            N.addPermission(jq.PERMISSION_INTERNET);
            N.addPermission(jq.PERMISSION_ACCESS_NETWORK_STATE);
            N.setupGoogleMap(googleMaps);
        }
        for (ProjectFileBean customView : projectFileManager.c()) {
            for (ViewBean viewBean : eC.a(projectDataManager.d(customView.getXmlName()))) {
                var classNameParts = viewBean.convert.split("\\.");
                var className = classNameParts[classNameParts.length - 1];
                switch (className) {
                    case "CircleImageView" -> N.x.isCircleImageViewUsed = true;
                    case "CodeView" -> N.x.isCodeViewUsed = true;
                    case "LottieAnimationView" -> N.x.isLottieUsed = true;
                    case "OTPView" -> N.x.isOTPViewUsed = true;
                    case "PatternLockView" -> N.x.isPatternLockViewUsed = true;
                    case "WaveSideBar" -> N.x.isWaveSideBarUsed = true;
                    case "YouTubePlayerView" -> N.x.isYoutubePlayerUsed = true;
                    case "SwipeRefreshLayout" -> N.x.isSwipeRefreshLayoutUsed = true;
                }
            }
        }
        for (ProjectFileBean activity : projectFileManager.b()) {
            if (activity.hasActivityOption(ProjectFileBean.OPTION_ACTIVITY_DRAWER)) {
                N.a(activity.getActivityName()).hasDrawer = true;
            }
            for (ComponentBean component : projectDataManager.e(activity.getJavaName())) {
                switch (component.type) {
                    case ComponentBean.COMPONENT_TYPE_CAMERA, 35 -> {
                        N.g = true;
                        N.u = true;
                        N.addPermission(activity.getActivityName(), jq.PERMISSION_CAMERA);
                        N.addPermission(activity.getActivityName(), jq.PERMISSION_READ_EXTERNAL_STORAGE);
                        N.addPermission(activity.getActivityName(), jq.PERMISSION_WRITE_EXTERNAL_STORAGE);
                    }
                    case ComponentBean.COMPONENT_TYPE_FILE_PICKER ->
                            N.addPermission(activity.getActivityName(), jq.PERMISSION_READ_EXTERNAL_STORAGE);
                    case ComponentBean.COMPONENT_TYPE_FIREBASE -> {
                        N.isGsonUsed = true;
                        N.isFirebaseDatabaseUsed = true;
                        N.addPermission(activity.getActivityName(), jq.PERMISSION_INTERNET);
                        N.addPermission(activity.getActivityName(), jq.PERMISSION_ACCESS_NETWORK_STATE);
                    }
                    case ComponentBean.COMPONENT_TYPE_FIREBASE_STORAGE -> {
                        N.isFirebaseStorageUsed = true;
                        N.addPermission(activity.getActivityName(), jq.PERMISSION_READ_EXTERNAL_STORAGE);
                        N.addPermission(activity.getActivityName(), jq.PERMISSION_WRITE_EXTERNAL_STORAGE);
                    }
                    case ComponentBean.COMPONENT_TYPE_VIBRATOR ->
                            N.addPermission(activity.getActivityName(), jq.PERMISSION_VIBRATE);
                    case ComponentBean.COMPONENT_TYPE_FIREBASE_AUTH -> {
                        N.isFirebaseAuthUsed = true;
                        N.a(activity.getActivityName()).usesFirebaseAuth = true;
                    }
                    case ComponentBean.COMPONENT_TYPE_REQUEST_NETWORK -> {
                        N.isGsonUsed = true;
                        N.isHttp3Used = true;
                        N.addPermission(activity.getActivityName(), jq.PERMISSION_INTERNET);
                        N.addPermission(activity.getActivityName(), jq.PERMISSION_ACCESS_NETWORK_STATE);
                    }
                    case ComponentBean.COMPONENT_TYPE_TEXT_TO_SPEECH -> N.isTextToSpeechUsed = true;
                    case ComponentBean.COMPONENT_TYPE_SPEECH_TO_TEXT -> {
                        N.isSpeechToTextUsed = true;
                        N.addPermission(activity.getActivityName(), jq.PERMISSION_RECORD_AUDIO);
                    }
                    case ComponentBean.COMPONENT_TYPE_BLUETOOTH_CONNECT -> {
                        N.addPermission(activity.getActivityName(), jq.PERMISSION_BLUETOOTH);
                        N.addPermission(activity.getActivityName(), jq.PERMISSION_BLUETOOTH_ADMIN);
                    }
                    case ComponentBean.COMPONENT_TYPE_LOCATION_MANAGER ->
                            N.addPermission(activity.getActivityName(), jq.PERMISSION_ACCESS_FINE_LOCATION);
                    case ComponentBean.COMPONENT_TYPE_FIREBASE_CLOUD_MESSAGE ->
                            N.x.isFCMUsed = true;
                    case ComponentBean.COMPONENT_TYPE_FIREBASE_AUTH_GOOGLE_LOGIN ->
                            N.x.isFBGoogleUsed = true;
                    default -> {
                    }
                }
            }

            for (ViewBean view : eC.a(projectDataManager.d(activity.getXmlName()))) {
                var classNameParts = view.convert.split("\\.");
                var className = classNameParts[classNameParts.length - 1];
                switch (className) {
                    case "CircleImageView" -> N.x.isCircleImageViewUsed = true;
                    case "CodeView" -> N.x.isCodeViewUsed = true;
                    case "LottieAnimationView" -> N.x.isLottieUsed = true;
                    case "OTPView" -> N.x.isOTPViewUsed = true;
                    case "PatternLockView" -> N.x.isPatternLockViewUsed = true;
                    case "WaveSideBar" -> N.x.isWaveSideBarUsed = true;
                    case "YouTubePlayerView" -> N.x.isYoutubePlayerUsed = true;
                    case "SwipeRefreshLayout" -> N.x.isSwipeRefreshLayoutUsed = true;
                }
            }

            for (Map.Entry<String, ArrayList<BlockBean>> entry : projectDataManager.b(activity.getJavaName()).entrySet()) {
                for (BlockBean block : entry.getValue()) {
                    switch (block.opCode) {
                        case "intentSetAction":
                            // If an Intent setAction (ACTION_CALL) block is used
                            if (block.parameters.get(1).equals(uq.c[1])) {
                                N.addPermission(activity.getActivityName(), jq.PERMISSION_CALL_PHONE);
                            }
                            break;

                        case "fileutilread":
                        case "fileutilisexist":
                        case "fileutillistdir":
                        case "fileutilisdir":
                        case "fileutilisfile":
                        case "fileutillength":
                        case "fileutilStartsWith":
                        case "fileutilEndsWith":
                        case "getJpegRotate":
                        case "setImageFilePath":
                        case "fileutilGetLastSegmentPath":
                            N.addPermission(activity.getActivityName(), jq.PERMISSION_READ_EXTERNAL_STORAGE);
                            break;

                        case "fileutilwrite":
                        case "fileutilcopy":
                        case "fileutilcopydir":
                        case "fileutilmove":
                        case "fileutildelete":
                        case "fileutilmakedir":
                        case "resizeBitmapFileRetainRatio":
                        case "resizeBitmapFileToSquare":
                        case "resizeBitmapFileToCircle":
                        case "resizeBitmapFileWithRoundedBorder":
                        case "cropBitmapFileFromCenter":
                        case "rotateBitmapFile":
                        case "scaleBitmapFile":
                        case "skewBitmapFile":
                        case "setBitmapFileColorFilter":
                        case "setBitmapFileBrightness":
                        case "setBitmapFileContrast":
                            N.addPermission(activity.getActivityName(), jq.PERMISSION_READ_EXTERNAL_STORAGE);
                            N.addPermission(activity.getActivityName(), jq.PERMISSION_WRITE_EXTERNAL_STORAGE);
                            break;

                        case "strToMap":
                        case "mapToStr":
                        case "strToListMap":
                        case "listMapToStr":
                        case "GsonListTojsonString":
                        case "GsonStringToListString":
                        case "GsonStringToListNumber":
                            N.isGsonUsed = true;
                            break;

                        case "setImageUrl":
                            N.isGlideUsed = true;
                            N.addPermission(jq.PERMISSION_INTERNET);
                            break;

                        case "webViewLoadUrl":
                            N.addPermission(jq.PERMISSION_INTERNET);
                            N.addPermission(jq.PERMISSION_ACCESS_NETWORK_STATE);
                            break;

                        default:
                    }
                }
            }
            N.b();
        }
    }

    /**
     * Generates the project's files, such as layouts, Java files, but also build.gradle and secrets.xml.
     */
    public void b(hC projectFileManager, eC projectDataManger, iC projectLibraryManager, BuiltInLibraryManager builtInLibraryManager) {
        ArrayList<SrcCodeBean> srcCodeBeans = a(projectFileManager, projectDataManger, builtInLibraryManager);
        if (N.u) {
            XmlBuilder pathsTag = new XmlBuilder("paths");
            pathsTag.addAttribute("xmlns", "android", "http://schemas.android.com/apk/res/android");
            XmlBuilder externalPathTag = new XmlBuilder("external-path");
            externalPathTag.addAttribute("", "name", "external_files");
            externalPathTag.addAttribute("", "path", ".");
            pathsTag.addChildNode(externalPathTag);
            srcCodeBeans.add(new SrcCodeBean("provider_paths.xml",
                    CommandBlock.applyCommands("xml/provider_paths.xml", pathsTag.toCode())));
        }

        for (SrcCodeBean bean : srcCodeBeans) {
            a(bean.srcFileName, bean.source);
        }
        if (N.isFirebaseEnabled || N.isAdMobEnabled || N.isMapUsed) {
            ProjectLibraryBean firebaseLibrary = projectLibraryManager.d();
            XmlBuilderHelper mx = new XmlBuilderHelper();
            mx.addInteger("google_play_services_version", 12451000);
            if (N.isFirebaseEnabled) {
                String databaseUrl;
                String projectId;
                String libraryData = firebaseLibrary.data;
                if (libraryData.contains(".")) {
                    databaseUrl = "https://" + libraryData;
                    projectId = libraryData.trim().replaceAll(FIREBASE_DATABASE_STORAGE_LOCATION_MATCHER, "");
                } else {
                    databaseUrl = "https://" + libraryData + ".firebaseio.com";
                    projectId = libraryData;
                }
                mx.addString("firebase_database_url", databaseUrl, false);
                mx.addString("project_id", projectId, false);
                mx.addString("google_app_id", firebaseLibrary.reserved1, false);
                if (firebaseLibrary.reserved2 != null && !firebaseLibrary.reserved2.isEmpty()) {
                    mx.addString("google_api_key", firebaseLibrary.reserved2, false);
                }
                if (firebaseLibrary.reserved3 != null && !firebaseLibrary.reserved3.isEmpty()) {
                    mx.addString("google_storage_bucket", firebaseLibrary.reserved3, false);
                }
            }
            if (N.isMapUsed) {
                // if p3 is false, then "translatable="false" will be added
                mx.addString("google_maps_key", projectLibraryManager.e().data, false);
            }
            String filePath = "values/secrets.xml";
            fileUtil.b(resDirectoryPath + File.separator + filePath,
                    CommandBlock.applyCommands(filePath, mx.toCode()));
        }
        generateGradleFiles();
    }

    /**
     * Get source code files that are viewable in SrcCodeViewer
     */
    public ArrayList<SrcCodeBean> a(hC projectFileManager, eC projectDataManager, BuiltInLibraryManager builtInLibraryManager) {
        generateDebugFiles(SketchApplication.getContext());
        CommandBlock.x();

        String javaDir = FileUtil.getExternalStorageDir() + "/.sketchware/data/" + sc_id + "/files/java/";
        String layoutDir = FileUtil.getExternalStorageDir() + "/.sketchware/data/" + sc_id + "/files/resource/layout/";
        List<File> javaFiles;
        {
            File[] files = new File(javaDir).listFiles();
            if (files == null) files = new File[0];
            javaFiles = Arrays.asList(files);
        }
        List<File> layoutFiles;
        {
            File[] files = new File(layoutDir).listFiles();
            if (files == null) files = new File[0];
            layoutFiles = Arrays.asList(files);
        }

        // Generate Activities unless a custom version of it exists already
        // at /Internal storage/.sketchware/data/<sc_id>/files/java/
        ArrayList<SrcCodeBean> srcCodeBeans = new ArrayList<>();
        for (ProjectFileBean activity : projectFileManager.b()) {
            if (!javaFiles.contains(new File(javaDir + activity.getJavaName()))) {
                srcCodeBeans.add(new SrcCodeBean(activity.getJavaName(),
                        new Jx(N, activity, projectDataManager).generateCode(isAndroidStudioExport, sc_id)));
            }
        }

        var path = wq.b(sc_id) + "/command";
        var newXMLCommand = Boolean.parseBoolean(projectSettings.getValue(ProjectSettings.SETTING_NEW_XML_COMMAND, ProjectSettings.SETTING_GENERIC_VALUE_FALSE));
        if (newXMLCommand && FileUtil.isExistFile(path)) {
            FileUtil.copyFile(path, FileUtil.getExternalStorageDir().concat("/.sketchware/temp/commands"));
        }

        var viewBindingBuilder = new ViewBindingBuilder(List.of(), new File("."), packageName);

        // Generate layouts unless a custom version of it exists already
        // at /Internal storage/.sketchware/data/<sc_id>/files/resource/layout/
        ArrayList<ProjectFileBean> regularLayouts = projectFileManager.b();
        for (ProjectFileBean layout : regularLayouts) {
            String xmlName = layout.getXmlName();
            Ox ox = new Ox(N, layout);
            ox.a(eC.a(projectDataManager.d(xmlName)), projectDataManager.h(xmlName));
            var ogFile = new File(layoutDir + xmlName);
            if (!layoutFiles.contains(ogFile)) {
                srcCodeBeans.add(new SrcCodeBean(xmlName, CommandBlock.applyCommands(xmlName, ox.b())));

                if (isViewBindingEnable()) {
                    var privFile = new File(context.getCacheDir(), xmlName);
                    FileUtil.writeFile(privFile.getAbsolutePath(), CommandBlock.applyCommands(xmlName, ox.b()));
                    var code = viewBindingBuilder.generateBindingForLayout(privFile);
                    srcCodeBeans.add(new SrcCodeBean(
                            ViewBindingBuilder.generateFileNameForLayout(xmlName.replace(".xml", "")) + ".java",
                            CommandBlock.applyCommands(xmlName, code)
                    ));
                }
            }
        }

        ArrayList<ProjectFileBean> customViewFiles = projectFileManager.c();
        for (ProjectFileBean customViewFile : customViewFiles) {
            String xmlName = customViewFile.getXmlName();
            Ox ox = new Ox(N, customViewFile);
            ox.a(eC.a(projectDataManager.d(xmlName)));
            var ogFile = new File(layoutDir + xmlName);
            if (!layoutFiles.contains(ogFile)) {
                srcCodeBeans.add(new SrcCodeBean(xmlName, CommandBlock.applyCommands(xmlName, ox.b())));

                if (isViewBindingEnable()) {
                    var privFile = new File(context.getCacheDir(), xmlName);
                    FileUtil.writeFile(privFile.getAbsolutePath(), CommandBlock.applyCommands(xmlName, ox.b()));
                    var code = viewBindingBuilder.generateBindingForLayout(privFile);
                    srcCodeBeans.add(new SrcCodeBean(
                            ViewBindingBuilder.generateFileNameForLayout(xmlName.replace(".xml", "")) + ".java",
                            CommandBlock.applyCommands(xmlName, code)
                    ));
                }
            }
        }

        Ix ix = new Ix(N, projectFileManager.b(), builtInLibraryManager);
        ix.setYq(this);

        // Make generated classes viewable
        if (!javaFiles.contains(new File(javaDir + "SketchwareUtil.java"))) {
            srcCodeBeans.add(new SrcCodeBean("SketchwareUtil.java",
                    Lx.i(packageName, material3LibraryManager.isMaterial3Enabled())));
        }

        if (!javaFiles.contains(new File(javaDir + "FileUtil.java"))) {
            srcCodeBeans.add(new SrcCodeBean("FileUtil.java",
                    Lx.e(packageName)));
        }

        if (!javaFiles.contains(new File(javaDir + "RequestNetwork.java")) && N.isHttp3Used) {
            srcCodeBeans.add(new SrcCodeBean("RequestNetwork.java",
                    Lx.j(Lx.h(packageName), false)));
        }

        if (!FileUtil.isExistFile(javaDir + "RequestNetworkController.java") && N.isHttp3Used) {
            srcCodeBeans.add(new SrcCodeBean("RequestNetworkController.java",
                    Lx.j(Lx.g(packageName), false)));
        }

        if (!javaFiles.contains(new File(javaDir + "BluetoothConnect.java")) && N.hasPermission(jq.PERMISSION_BLUETOOTH)) {
            srcCodeBeans.add(new SrcCodeBean("BluetoothConnect.java",
                    Lx.j(Lx.b(packageName), false)));
        }

        if (!javaFiles.contains(new File(javaDir + "BluetoothController.java")) && N.hasPermission(jq.PERMISSION_BLUETOOTH)) {
            srcCodeBeans.add(new SrcCodeBean("BluetoothController.java",
                    Lx.j(Lx.c(packageName), false)));
        }

        if (N.isMapUsed) {
            if (!javaFiles.contains(new File(javaDir + "GoogleMapController.java")) && N.isMapUsed) {
                srcCodeBeans.add(new SrcCodeBean("GoogleMapController.java",
                        Lx.j(Lx.f(packageName), false)));
            }
        }

        srcCodeBeans.add(new SrcCodeBean("AndroidManifest.xml", CommandBlock.applyCommands("AndroidManifest.xml", ix.a())));
        srcCodeBeans.add(new SrcCodeBean("styles.xml", getXMLStyle()));
        srcCodeBeans.add(new SrcCodeBean("colors.xml", getXMLColor()));
        srcCodeBeans.add(new SrcCodeBean("strings.xml", getXMLString()));
        CommandBlock.x();
        return srcCodeBeans;
    }

    private boolean isViewBindingEnable() {
        return generateDataBindingClasses && projectSettings.getValue(ProjectSettings.SETTING_ENABLE_VIEWBINDING, ProjectSettings.SETTING_GENERIC_VALUE_FALSE).equals(ProjectSettings.SETTING_GENERIC_VALUE_TRUE);
    }

    /**
     * Get generated source code of a file.
     *
     * @return The file's code or an empty String if not found
     */
    public String getFileSrc(String filename, hC projectFileManager, eC projectDataManager, iC projectLibraryManager) {
        a(projectLibraryManager, projectFileManager, projectDataManager);
        CommandBlock.x();
        boolean isJavaFile = filename.endsWith(".java");
        boolean isXmlFile = filename.endsWith(".xml");
        boolean isManifestFile = filename.equals("AndroidManifest.xml");
        ArrayList<ProjectFileBean> files = new ArrayList<>(projectFileManager.b());
        files.addAll(new ArrayList<>(projectFileManager.c()));
        if (isXmlFile) {
            var path = wq.b(sc_id) + "/command";
            var newXMLCommand = Boolean.parseBoolean(projectSettings.getValue(ProjectSettings.SETTING_NEW_XML_COMMAND, ProjectSettings.SETTING_GENERIC_VALUE_FALSE));
            if (newXMLCommand && FileUtil.isExistFile(path)) {
                FileUtil.copyFile(path, FileUtil.getExternalStorageDir().concat("/.sketchware/temp/commands"));
            } else {
                /*
                 Generating every java file is necessary to make command blocks for xml work
                 */
                for (ProjectFileBean file : files) {
                    CommandBlock.CBForXml(new Jx(N, file, projectDataManager).generateCode(isAndroidStudioExport, sc_id));
                }
            }
        }

        switch (filename) {
            case "strings.xml" -> {
                return getXMLString();
            }
            case "colors.xml" -> {
                return getXMLColor();
            }
            case "styles.xml" -> {
                return getXMLStyle();
            }
        }

        if (isManifestFile) {
            ProjectBuilder builder = new ProjectBuilder(SketchApplication.getContext(), this);
            builder.buildBuiltInLibraryInformation();
            Ix ix = new Ix(N, projectFileManager.b(), builder.getBuiltInLibraryManager());
            ix.setYq(this);
            return CommandBlock.applyCommands("AndroidManifest.xml", ix.a());
        }

        for (ProjectFileBean file : files) {
            if (filename.equals(isJavaFile ? file.getJavaName() : file.getXmlName())) {
                if (isJavaFile) {
                    return new Jx(N, file, projectDataManager).generateCode(isAndroidStudioExport, sc_id);
                } else if (isXmlFile) {
                    Ox xmlGenerator = new Ox(N, file);
                    xmlGenerator.a(eC.a(projectDataManager.d(filename)), projectDataManager.h(filename));
                    return CommandBlock.applyCommands(filename, xmlGenerator.b());
                }
            }
        }

        return "";
    }

    public String getXMLString() {
        String filePath = wq.b(sc_id) + "/files/resource/values/strings.xml";
        if (FileUtil.isExistFile(filePath) && exportingType == ExportType.SOURCE_CODE_VIEWING) {
            return FileUtil.readFile(filePath);
        }
        XmlBuilderHelper stringsFileBuilder = new XmlBuilderHelper();
        stringsFileBuilder.addNonTranslatableString("app_name", applicationName);
        return CommandBlock.applyCommands("strings.xml", stringsFileBuilder.toCode());
    }

    public String getXMLColor() {
        String filePath = wq.b(sc_id) + "/files/resource/values/colors.xml";
        if (FileUtil.isExistFile(filePath) && exportingType == ExportType.SOURCE_CODE_VIEWING) {
            return FileUtil.readFile(filePath);
        }
        XmlBuilderHelper colorsFileBuilder = new XmlBuilderHelper();
        colorsFileBuilder.addColor("colorPrimary", String.format("#%06X", colorPrimary & 0xffffff));
        colorsFileBuilder.addColor("colorPrimaryDark", String.format("#%06X", colorPrimaryDark & 0xffffff));
        colorsFileBuilder.addColor("colorAccent", String.format("#%06X", colorAccent & 0xffffff));
        colorsFileBuilder.addColor("colorControlHighlight", String.format("#%06X", colorControlHighlight & 0xffffff));
        colorsFileBuilder.addColor("colorControlNormal", String.format("#%06X", colorControlNormal & 0xffffff));
        return CommandBlock.applyCommands("colors.xml", colorsFileBuilder.toCode());
    }

    public String getXMLStyle() {
        String filePath = wq.b(sc_id) + "/files/resource/values/styles.xml";
        if (FileUtil.isExistFile(filePath) && exportingType == ExportType.SOURCE_CODE_VIEWING) {
            return FileUtil.readFile(filePath);
        }
        if (material3LibraryManager.isMaterial3Enabled()) {
            XmlBuilderHelper stylesFileBuilder = new XmlBuilderHelper();
            stylesFileBuilder.addStyle("AppTheme", String.format("Theme.Material3.%s.NoActionBar", material3LibraryManager.getTheme()));
            stylesFileBuilder.addItemToStyle("AppTheme", "android:statusBarColor", "@android:color/transparent");
            stylesFileBuilder.addItemToStyle("AppTheme", "android:navigationBarColor", "@android:color/transparent");
            stylesFileBuilder.addItemToStyle("AppTheme", "android:windowLightStatusBar", "?attr/isLightTheme");
            stylesFileBuilder.addStyle("AppTheme.FullScreen", "AppTheme");
            stylesFileBuilder.addItemToStyle("AppTheme.FullScreen", "android:windowFullscreen", "true");
            stylesFileBuilder.addItemToStyle("AppTheme.FullScreen", "android:windowContentOverlay", "@null");
            stylesFileBuilder.addStyle("AppTheme.AppBarOverlay", "ThemeOverlay.Material3");
            stylesFileBuilder.addStyle("AppTheme.PopupOverlay", "ThemeOverlay.Material3");
            stylesFileBuilder.addStyle("AppTheme.DebugActivity", "AppTheme");
            stylesFileBuilder.addItemToStyle("AppTheme.DebugActivity", "windowActionBar", "true");
            stylesFileBuilder.addItemToStyle("AppTheme.DebugActivity", "windowNoTitle", "false");
            return CommandBlock.applyCommands("styles.xml", stylesFileBuilder.toCode());
        } else if (N.g) {
            boolean useNewMaterialComponentsTheme = projectSettings.getValue(ProjectSettings.SETTING_ENABLE_BRIDGELESS_THEMES,
                    BuildSettings.SETTING_GENERIC_VALUE_FALSE).equals(BuildSettings.SETTING_GENERIC_VALUE_TRUE);
            XmlBuilderHelper stylesFileBuilder = new XmlBuilderHelper();
            stylesFileBuilder.addStyle("AppTheme", "Theme.MaterialComponents.Light.NoActionBar" + (useNewMaterialComponentsTheme ? "" : ".Bridge"));
            // todo: add 'colorOnPrimary' to custom theme colors.
            stylesFileBuilder.addItemToStyle("AppTheme", "colorOnPrimary", "@android:color/white");
            stylesFileBuilder.addItemToStyle("AppTheme", "colorPrimary", "@color/colorPrimary");
            stylesFileBuilder.addItemToStyle("AppTheme", "colorPrimaryDark", "@color/colorPrimaryDark");
            stylesFileBuilder.addItemToStyle("AppTheme", "colorAccent", "@color/colorAccent");
            stylesFileBuilder.addItemToStyle("AppTheme", "colorControlHighlight", "@color/colorControlHighlight");
            stylesFileBuilder.addItemToStyle("AppTheme", "colorControlNormal", "@color/colorControlNormal");

            stylesFileBuilder.addStyle("AppTheme.FullScreen", "AppTheme");
            stylesFileBuilder.addItemToStyle("AppTheme.FullScreen", "android:windowFullscreen", "true");
            stylesFileBuilder.addItemToStyle("AppTheme.FullScreen", "android:windowContentOverlay", "@null");

            stylesFileBuilder.addStyle("AppTheme.AppBarOverlay", "ThemeOverlay.MaterialComponents.Dark.ActionBar");
            stylesFileBuilder.addStyle("AppTheme.PopupOverlay", "ThemeOverlay.MaterialComponents.Light");

            stylesFileBuilder.addStyle("AppTheme.DebugActivity", "AppTheme");
            stylesFileBuilder.addItemToStyle("AppTheme.DebugActivity", "actionBarStyle", "@style/ThemeOverlay.MaterialComponents.ActionBar.Primary");
            stylesFileBuilder.addItemToStyle("AppTheme.DebugActivity", "actionBarTheme", "@style/Widget.MaterialComponents.ActionBar.Primary");
            stylesFileBuilder.addItemToStyle("AppTheme.DebugActivity", "windowActionBar", "true");
            stylesFileBuilder.addItemToStyle("AppTheme.DebugActivity", "windowNoTitle", "false");
            return CommandBlock.applyCommands("styles.xml", stylesFileBuilder.toCode());
        } else {
            XmlBuilderHelper stylesFileBuilder = new XmlBuilderHelper();
            stylesFileBuilder.addStyle("AppTheme", "@android:style/Theme.Material.Light.DarkActionBar");
            stylesFileBuilder.addItemToStyle("AppTheme", "android:colorPrimary", "@color/colorPrimary");
            stylesFileBuilder.addItemToStyle("AppTheme", "android:colorPrimaryDark", "@color/colorPrimaryDark");
            stylesFileBuilder.addItemToStyle("AppTheme", "android:colorAccent", "@color/colorAccent");
            stylesFileBuilder.addItemToStyle("AppTheme", "android:colorControlHighlight", "@color/colorControlHighlight");
            stylesFileBuilder.addItemToStyle("AppTheme", "android:colorControlNormal", "@color/colorControlNormal");
            stylesFileBuilder.addStyle("FullScreen", "@android:style/Theme.Material.Light.NoActionBar.Fullscreen");
            stylesFileBuilder.addItemToStyle("FullScreen", "android:colorPrimary", "@color/colorPrimary");
            stylesFileBuilder.addItemToStyle("FullScreen", "android:colorPrimaryDark", "@color/colorPrimaryDark");
            stylesFileBuilder.addItemToStyle("FullScreen", "android:colorAccent", "@color/colorAccent");
            stylesFileBuilder.addItemToStyle("FullScreen", "android:colorControlHighlight", "@color/colorControlHighlight");
            stylesFileBuilder.addItemToStyle("FullScreen", "android:colorControlNormal", "@color/colorControlNormal");
            stylesFileBuilder.addStyle("NoActionBar", "@android:style/Theme.Material.Light.NoActionBar");
            stylesFileBuilder.addItemToStyle("NoActionBar", "android:colorPrimary", "@color/colorPrimary");
            stylesFileBuilder.addItemToStyle("NoActionBar", "android:colorPrimaryDark", "@color/colorPrimaryDark");
            stylesFileBuilder.addItemToStyle("NoActionBar", "android:colorAccent", "@color/colorAccent");
            stylesFileBuilder.addItemToStyle("NoActionBar", "android:colorControlHighlight", "@color/colorControlHighlight");
            stylesFileBuilder.addItemToStyle("NoActionBar", "android:colorControlNormal", "@color/colorControlNormal");
            stylesFileBuilder.addStyle("NoStatusBar", "AppTheme");
            stylesFileBuilder.addItemToStyle("NoStatusBar", "android:windowFullscreen", "true");
            stylesFileBuilder.addStyle("AppTheme.DebugActivity", "AppTheme");
            return CommandBlock.applyCommands("styles.xml", stylesFileBuilder.toCode());
        }
    }

    public enum ExportType {
        AAB,
        SIGN_APP,
        DEBUG_APP,
        ANDROID_STUDIO,
        SOURCE_CODE_VIEWING
    }
}
